<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>

        <a-card>
            <div class="table-operator">
                <a-button type="primary" icon="plus" @click="handleAdd" v-btnPermission="'bm_004_add_01'"
                    >新增</a-button
                >
                <div class="table-operateors mb20">
                    <div class="pub-table-select-count">
                        <a-icon type="info-circle" theme="twoTone" />
                        <span>
                            总立项金额(不含税)(万元)：
                            <a>{{ from.projectTotalAmount }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            总立项金额占比自施合同额：
                            <a>{{ from.projectTotalAmountRate }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            已确认效益(不含税)(万元)：
                            <a>{{ from.confirmBenefits }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            按阶段项数确认率：
                            <a>{{ from.projectConfirmRate }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            按阶段效益确认率：
                            <a>{{ from.benefitsConfirmRate }}</a>
                        </span>
                        <a-divider type="vertical" />
                        <span>
                            优化效益率(不含税)：
                            <a>{{ from.optimizeBenefitsRate }}</a>
                        </span>
                    </div>
                </div>
            </div>
            <list-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="detailed(record)" v-btnPermission="'bm_004_loo_04'">查看</a>
                    <a
                        @click="addEdit(record)"
                        v-if="
                            record.auditStatus != 'SUBMITTED' &&
                            record.auditStatus != 'PAST' &&
                            record.auditStatus != 'ABOLISH'
                        "
                        v-btnPermission="'bm_004_edi_02'"
                        >编辑</a
                    >
                    <a
                        @click="deleteDraft(record, 1, '撤销')"
                        v-if="
                            record.auditStatus == 'SUBMITTED' &&
                            record.planBookType == 'INIT' &&
                            userId === record.creatorId&&hideBuquBtn()
                        "
                        >撤销</a
                    >
                    <a
                        @click="deleteDraft(record, 2, '作废')"
                        v-if="record.auditStatus == 'PAST'"
                        v-btnPermission="'bm_004_tov_05'"
                        >作废</a
                    >
                    <a
                        @click="deleteDraft(record, 0, '删除')"
                        v-if="
                            record.auditStatus == 'DRAFT' ||
                            record.auditStatus == 'REJECTED' ||
                            (record.auditStatus == 'SUBMITTED' && record.planBookType == 'ADJUST')
                        "
                        v-btnPermission="'bm_004_del_03'"
                        >删除</a
                    >
                    <span
                        v-if="
                            (record.auditStatus === 'PAST' ||
                                record.auditStatus === 'SUBMITTED' ||
                                record.auditStatus === 'REJECTED' ||
                                record.auditStatus === 'ABOLISH') &&
                            record.planBookType == 'INIT'
                        "
                        v-btnPermission="'bm_004_loo_04'"
                    >
                        <approval-button
                            :status="record.auditStatus"
                            :id="record.id"
                        ></approval-button>
                    </span>
                </MoreButton>
                </span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="record.planBookType == 'INIT'"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { recordList, eliminate, cancel, getListCount } from '@/api/businessAffairs/planBook'
const columns = [
    {
        title: '所属分公司',
        dataIndex: 'branchComName'
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
        width: 300
    },
    {
        title: '月份',
        dataIndex: 'month',
        width: 100
    },
    {
        title: '商务策划类型',
        dataIndex: 'planBookTypeStr'
    },
    {
        title: '总立项金额(不含税)(万元)',
        dataIndex: 'projectTotalAmount',
        width: 130
    },
    {
        title: '总立项金额占比自施合同额',
        dataIndex: 'projectTotalAmountRate',
        width: 120
    },
    {
        title: '已确认效益(不含税)(万元)',
        dataIndex: 'confirmBenefits',
        width: 130
    },
    {
        title: '优化效益率(不含税)(%)',
        dataIndex: 'optimizeBenefitsRate',
          width: 120
    },
    {
        title: '填报人',
        dataIndex: 'creatorName'
    },
    {
        title: '填报时间',
        dataIndex: 'createTime'
    },
    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' }
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        fixed: 'right',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },

    {
        name: '月份',
        type: 'month',
        value: 'month',
        attrs: {
            valueFormat: 'YYYY-MM'
        }
    },
    {
        name: '商务策划书类型',
        value: 'planBookType',
        type: 'select',
        data: [
            {
                value: 'INIT',
                label: '初版'
            },
            {
                value: 'ADJUST',
                label: '动态调整'
            }
        ]
    },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input'
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange'
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: '6',
                label: '未提交'
            },
            {
                value: '7',
                label: '已提交'
            },
            {
                value: '0',
                label: '待提交审批'
            },
            {
                value: '1',
                label: '审批中'
            },
            {
                value: '2',
                label: '审批通过'
            },
            {
                value: '3',
                label: '审批不通过'
            },
            {
                value: '5',
                label: '已作废'
            }
        ]
    }
]
import { typeListApproval } from '@/utils/util'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分公司
import { STable } from '@/components'
export default {
    name: 'a' + Date.now(),
    components: {
        STable
    },

    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            from: {},
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)

                if (this.queryParam.startEndDate) {
                    requestParameters.createTimeBegin =
                        this.queryParam.startEndDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.createTimeEnd =
                        this.queryParam.startEndDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }
                this.getListCount(requestParameters)
                return recordList(requestParameters).then((res) => {
                    console.log('数据返回对象：', res)
                    return res
                })
            }
        }
    },
    methods: {
        getListCount(requestParameters) {
            getListCount(requestParameters).then((res) => {
                this.from = res.data
            })
        },
        //搜索
        search(value) {
            console.log(value)
            this.queryParam = value
            this.$refs.table.refresh(true)
        },
        //新增
        handleAdd() {
            this.$router.push('/businessAffairs/planBook/newIncrease')
        },
        // 查看
        detailed(e) {
            this.$router.push({
                path: '/businessAffairs/planBook/newIncrease',
                query: { id: e.id, pageType: 'look' }
            })
        },
        //编辑
        addEdit(e) {
            this.$router.push({
                path: '/businessAffairs/planBook/newIncrease',
                query: { id: e.id, pageType: 'edit' }
            })
        },
        // 删除草稿
        deleteDraft(e, type, text) {
            let that = this

            that.$confirm({
                title: '温馨提示',
                content: '确定是否' + text + '数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    if (type == 0) {
                        return eliminate({ id: e.id })
                            .then((res) => {
                                that.$message.success('删除成功！')
                                that.$refs.table.refresh(true)
                            })
                            .catch((res) => {
                                that.$message.warning('删除失败！')
                            })
                    } else {
                        return cancel({ id: e.id, type: type })
                            .then((res) => {
                                that.$message.success(text + '成功！')
                                that.$refs.table.refresh(true)
                            })
                            .catch((res) => {
                                that.$message.warning(text + '失败！')
                            })
                    }
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
@deep: ~'>>>';
.tool-btns {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}
</style>

